﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MRS.DBL.Model;
using MRSUtil;
using System.Reflection;

namespace MRS.DBL.BLL
{
    public class IndustryMgr
    {
        static log4net.ILog logger = log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);

        private readonly DAL.IndustryDAL _Dal = new DAL.IndustryDAL();

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool ExistsIndustry(string name,int industryId)
        {
            return _Dal.Exists(name,industryId);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int AddIndustry(Model.IndustryModel model)
        {
            if (ExistsIndustry(model.IndustryName,model.Id))
                return MRSConsts.Code_Exists;
            return _Dal.Add(model);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public int UpdateIndustry( MRS.DBL.Model.IndustryModel model)
        {
            if (ExistsIndustry(model.IndustryName, model.Id))
                return MRSConsts.Code_Exists;
            int result = _Dal.Update(model);
            if (result >= 0)
                return MRSConsts.Code_Success;
            else
                return MRSConsts.Code_Error;
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool DeleteIndustry(int Id)
        {

            return _Dal.Delete(Id);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public MRS.DBL.Model.IndustryModel GetIndustryModel(int Id)
        {

            return _Dal.GetModel(Id);
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public MRS.DBL.Model.IndustryModel[] GetIndustryList()
        {
            return _Dal.GetList();
        }
    }
}
